app.controller("taskCtrl",function($rootScope,$scope,httpService,$timeout,toaster,wtmapService,$parse){$scope.RecordType=wtSys.Emun.RecordType,$scope.DeviceStatus=wtSys.Emun.DeviceStatus,//隐患状态
$scope.taskTypes=wtSys.Emun.taskTypes,//计划类型
$scope.searchList=[{typeName:"状态",typeList:[{id:1,name:"未开始"},{id:2,name:"进行中"},{id:2,name:"已结束"}]}],/**
     * 绘制定位点配置
     * @type {{layerid: string, 图层ID
     * symbolUrl: string 定位点图片Url }}
     */
$scope.pointOption={
//layerid:图形图层id
layerid:"locationLayer",symbolUrl:"/assets/img/gps_location.png"},/*==============设置选择设施位置信息 Begin=============================*/
//设置选择设施位置信息
$scope.isShowSetPosition=!1,/**
     * 打开 选择设位置panel
     */
$scope.openSetPositionPanel=function(){$scope.isShowSetPosition=!0},/**
         * 关闭 选择设位置panel
         */
$scope.closeSetPositionPanel=function(){$scope.isShowSetPosition=!1,
// 获取被选中的点的数据
$scope.deviceModel.Lng=$scope.selectedPosition.x,$scope.deviceModel.Lat=$scope.selectedPosition.y},$scope.setPositionOption={mapid:"setPosition",center:{x:155307.451,y:139762.144,lng:0,lat:0},zoom:3,height:600,showgdmap:!1},
//Edit状态默认被选中的点坐标
$scope.selectedPosition={x:0,y:0},/*==============设置选择设施位置信息 End=============================*/
// 日期组件
$scope.openDate=function($event,key){$event.preventDefault(),$event.stopPropagation(),key&&$parse(key).assign($scope,!0)},
// 初始化查询变量
$scope.initParam=function(){$scope.deviceList=[],$scope.page=1,$scope.busy=!1,$scope.limit=10,$scope.isGetDetailTag=!0},$scope.edit=function(Id,index){
// 还原表单以及表单值
$scope.deviceForm.$setPristine(),Id||0==Id?($scope.deviceId=Id,$scope.index=index,$scope.editModalTitle="修改周期计划",$scope.getDeviceDetail($scope.deviceId)):($scope.deviceId=null,$scope.index=null,$scope.deviceModel={Name:"",Code:"",RFID:"",Lat:0,Lng:0,Addr:"",DeviceTypeId:null,Contact:"",Phone:"",StartAt:"",EndAt:"",Spec:"",UseDept:"",Ext:"",Imgs:[]},$scope.editModalTitle="新增周期计划"),$("#editModal").modal("show")},
//设施表单提交
$scope.deviceFormSubmit=function(){$scope.deviceForm.$invalid=!0;var path="/device",type="POST";$scope.deviceId&&(path="/device/"+$scope.deviceId,type="PUT"),httpService.request(type,path,$scope.deviceModel,function(result){$scope.deviceForm.$invalid=!1,toaster.pop("success","提示",result.message),$("#editModal").modal("hide");
// 更新列表数据
var arr=$scope.deviceList;null!=$scope.index&&$scope.index>=0?arr[$scope.index]=result.data:(arr.unshift(result.data),$scope.activeId=result.data.Id),$scope.deviceList=arr})},
//删除设施弹框处理
$scope.del=function(item,index){$scope.index=index,$scope.delModel=angular.copy(item),$("#delModal").modal("show")},
//确认删除设施
$scope.delConfirm=function(){$("#delModal").modal("hide");var path="/device/"+$scope.delModel.Id;httpService.request("DELETE",path,null,function(result){toaster.pop("success","提示",result.message);
// 更新列表数据
var arr=$scope.deviceList;arr.splice($scope.index,1),$scope.deviceList=arr,
//如果删除的是第一条数据,删除成功后重新设置activeId的值
0==$scope.index&&($scope.activeId=arr[0]?arr[0].Id:null)})},
//获取设施列表
$scope.getDeviceList=function(){if($scope.busy)return!1;var path="/device?page="+$scope.page+"&limit="+$scope.limit;// '/device?page=1&limit=40';
$scope.busy=!0,httpService.request("GET",path,null,function(result){if(angular.forEach(result.data,function(data,i){$scope.deviceList.push(data)}),result.data.length>=$scope.limit&&($scope.busy=!1,$scope.page+=1),$scope.deviceList.length>0&&$scope.isGetDetailTag){$scope.isGetDetailTag=!1;var arr=$scope.deviceList;$scope.activeId=arr[0].Id}})},
//获取设施详情
$scope.getDeviceDetail=function(Id,isRgt){var path="/device/"+Id;httpService.request("GET",path,null,function(result){isRgt?$scope.deviceDetailModel=result.data:$scope.deviceModel=result.data,$scope.deviceLocation()})},
//获取设施类型
$scope.getDeviceType=function(){var path="/devicetype";httpService.request("GET",path,null,function(result){$scope.deviceTypeList=result.data})},
//获取右侧model
$scope.getRgtModel=function(){
//点击列表重置查询参数
$scope.activeId&&($scope.getDeviceDetail($scope.activeId,!0),//获取设施详情
$scope.recordList=[],$scope.recordPage=1,$scope.recordBusy=!1,$scope.getRecordList())},
//获取设施记录列表
$scope.getRecordList=function(){if($scope.recordBusy)return!1;var path="/record?deviceid="+$scope.activeId+"&page="+$scope.recordPage+"&limit="+$scope.limit;$scope.recordBusy=!0,httpService.request("GET",path,null,function(result){angular.forEach(result.data,function(data,i){$scope.recordList.push(data)}),result.data.length>=$scope.limit&&($scope.recordBusy=!1,$scope.recordPage+=1)})},/**
         * 设施定位操作
         * @param id 传入设施id
         *
         */
$scope.deviceLocation=function(){$scope.mapobj&&$scope.mapobj.drawApi.clearGraphics($scope.pointOption.layerid),$scope.deviceDetailModel&&$scope.deviceDetailModel.Lng?($scope.mapobj.drawApi.drawPoint($scope.deviceDetailModel.Lng,$scope.deviceDetailModel.Lat,$scope.pointOption),$scope.mapobj.zoomTobyXY($scope.deviceDetailModel.Lng,$scope.deviceDetailModel.Lat,5)):toaster.warning("提示","您选择的设备还未进行定位!")},
//地图高度
$scope.mapheight=$(".rgt-wrap").height()-85||700,$scope.mapService=wtmapService,
// 地图初始化
$scope.mapIntialed=function(scope){var promise=wtmapService.intialMap("map1",!1,0,$rootScope.arcgisConfig.lods);//同步调用，获取承诺接口
promise.then(function(mapobj){mapobj.addDynamicMap($rootScope.arcgisConfig.baseMap),mapobj.addFeatureLayer("设备点",{maxScale:0,minScale:0,showInfoTemplate:!1}),mapobj.zoomTobyXY(175307.451,135762.144,1),$scope.mapobj=mapobj,
//获取设施列表
$scope.getDeviceList()},function(data){})},$scope.initParam(),// 初始化查询列表变量
$scope.getDeviceType()});